//在线列表
"use strict"
exports.index = async function(){
    //console.log(this.req);
    this.view = "branch/online";
    let branch=this.branch;
    //拉出服务器
    let server = this.model.branch("server",branch);
    let keys = ["name","status"]
    let ret= await server.mget(keys);
    let data={server:[]};
    let query_list=[];
    for(let k in ret){
        let v = ret[k];
        let d={};
        if(v._id>=900){
            continue;
        }
        if(v.status==9){
            continue;
        }
        d.sid=v._id;
        d.sname=v.name;
        data.server.push(d);
        try{
            query_list.push(this.library("game/request",branch,d.sid,'/online/list',{}));
        }catch(err){
            console.log(err);
        }
    }

    let rets=await Promise.all(query_list);

    for(let i=0;i<rets.length;++i){
        if(rets[i]){
            data.server[i]=Object.assign(data.server[i],rets[i]);
        }
        else{
            data.server[i]=Object.assign(data.server[i],{num:0,pnum:0,anum:0,income:0});
        }
    }
    data['bpath'] = ['', 'b', branch].join('/');
    return data;
}

